"use strict";

uk.create_card=function(cardid){
    if(!uk.cache.cardmap.hasOwnProperty(cardid)){
        console.log('create_card failed,invalid cardid:'+cardid);
        return null;
    }
    var cc = uk.cache.cardmap[cardid];
    var c = {};
    c.id = uk.getnewguidn();
    c.template = cc;
    c.back = cardid == 0 ? uk.game.add.image(-300,-300,'cardback'):uk.game.add.image(-300,-300,'cardforce');
    if(c.back == null){
        console.log('load card base image failed');
    }
    if(cardid != 0){
        var cardimg = uk.game.add.image(5,33,'card_'+cardid);
        if(cardimg == null){
            console.log('load card image failed:'+cardid);
        }else{
            c.back.addChild(cardimg);
        }
        c.cost = uk.game.add.image(3,1,'cardsign',0);
        c.costtxt = uk.game.add.text(c.cost.width/2,c.cost.height/2+2,'0',uk.uidata.fontstyle.cardsign);
        c.cost.addChild(c.costtxt);
        c.back.addChild(c.cost);
        c.costtxt.anchor.set(0.5);
        c.costtxt.text = cc.cost;

        c.sign = uk.game.add.image(84,1,'cardsign',cc.sign);
        c.signtxt = uk.game.add.text(c.sign.width/2,c.sign.height/2+2,'0',uk.uidata.fontstyle.cardsign);
        c.sign.addChild(c.signtxt);
        c.back.addChild(c.sign);
        c.signtxt.anchor.set(0.5);
        c.signtxt.text = cc.signval;
        
        c.nametxt = uk.game.add.text(c.back.width/2,c.back.height-16,'',uk.uidata.fontstyle.cardname);
        c.back.addChild(c.nametxt);
        c.nametxt.anchor.set(0.5);
        c.nametxt.text = cc.name;
    }
    c.destroy=function(){
        if(c.back) c.cost.destroy();
        c.back = null;
    }
    return c;
}